﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model.Enum;
using System.Data;
using System.Text;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;

namespace HZ.Supervise.Web.Secondphase.NewReport
{
    public partial class PrintComStatistics : BasePage
    {

        public PrintComStatistics()
        {
            this.ModuleNo = Module.企业统计分析.ToString();
            this.PageOperateType = OperateType.支付单.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(Request.QueryString["sesid"]))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('页面跳转时未能将信息传递到本页面，请在页面返回后重试！');window.close();</script>");
            }
            else
            {
                BindDate();
            }
        }

        protected void BindDate()
        {
            HZ.Supervise.Model.SuperviseQuery vs = (SuperviseQuery) Session[ Request.QueryString["sesid"]];
            IBLL_Statistics ibs = HZ.Supervise.BLLFactory.IBLL_Statistics();

            DataTable dtdetail = ibs.GetCompanyAmountStatistics(vs);

            if (dtdetail.Rows.Count > 0)
            {
                AmountConvertToChinese actc = new AmountConvertToChinese();
                
                StringBuilder str = new StringBuilder();
                decimal warehouseamount = 0;
                decimal returnamount = 0;
                decimal payamount = 0;
                for (int i = 0; i < dtdetail.Rows.Count; i++)
                {
                    str.Append("<tr><td>");
                    str.Append((i + 1) + "");
                    str.Append("</td><td>");
                    str.Append(dtdetail.Rows[i]["CompanyName"].ToString());
                    str.Append("</td><td>");
                    str.Append(dtdetail.Rows[i]["WarehouseMonth"].ToString());
                    str.Append("</td><td>");
                    str.Append(dtdetail.Rows[i]["WarehouseAmount"].ToString());
                    str.Append("</td><td>");
                    str.Append(dtdetail.Rows[i]["ReturnAmount"].ToString());
                    str.Append("</td><td>");
                    str.Append(dtdetail.Rows[i]["PayAmount"].ToString());
                    str.Append("</td></tr>");
                    warehouseamount += Convert.ToDecimal(dtdetail.Rows[i]["WarehouseAmount"].ToString());
                    returnamount += Convert.ToDecimal(dtdetail.Rows[i]["ReturnAmount"].ToString());
                    payamount += Convert.ToDecimal(dtdetail.Rows[i]["PayAmount"].ToString());
                }
                str.Append("<tr><td>");
                str.Append("");//(dtdetail.Rows.Count + 1) + "");
                str.Append("</td><td>");
                str.Append("合计：");
                str.Append("</td><td>");
                str.Append("");
                str.Append("</td><td>");
                str.Append(warehouseamount.ToString());
                str.Append("</td><td>");
                str.Append(returnamount.ToString());
                str.Append("</td><td>");
                str.Append(payamount.ToString());
                str.Append("</td></tr>");
                litContent.Text = str.ToString();
                btnPrintDetail.Visible = true;
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('所选地区在所选时间段内无数据，请重新填写条件！');</script>");
                btnPrintDetail.Visible = false;
            }
        }
    }
}
